<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="|#{customer.systemTitle}-内容管理-投票管理|">图灵谷</title>
<div th:replace="fragments/head_admin">head</div>
<!--/***** 当前页css  start *****/-->
<!--/***** 当前页css  end *****/-->
</head>
<body>
	<div class="layui-layout layui-layout-admin">
		<div th:replace="fragments/nav_admin">导航栏</div>
		<div th:replace="fragments/menu_admin::menu(parent=content,child=question)">菜单栏</div>
		<!--/*******内容*******/-->
		<div class="layui-body layui-tab-content site-demo site-demo-body">
			<div class="layui-tab-item layui-show">
				<div class="layui-main">
					<!--/***** 面包屑 *****/-->
					<div class="layui-elem-quote" style="margin-top: 10px;">
						<span class="layui-breadcrumb"> <a><cite>内容管理</cite></a><a th:href="@{/admin/m/ext/vote/list.gsp}">投票管理</a><a><cite>列表</cite></a>
						</span>
					</div>
					<!--/***** 列表 *****/-->
					<div class="layui-form-item">
						<div class="layui-inline" style="width: 35%;">
							<fieldset class="layui-elem-field">
								<legend>问卷管理</legend>
								<div class="layui-field-box">
									<table class="layui-table" lay-even="" lay-skin="row">
										<thead id="dataTable">
											<tr>
												<th style="width: 40px">#</th>
												<th>状态</th>
												<th>问卷标题</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
											<!-- <tr th:if="${questionList.records == null or questionList.records.size() == 0}">
                                                <td colspan="4" style="text-align: center;">暂时没有数据</td>
                                            </tr>
                                            <tr th:each="item,items:${questionList.records}">
                                                <td th:text="${questionList.pageSize*(questionList.page-1)+items.index+1}" style="text-align: center;">序号</td>
                                                <td th:text="${item.enabled==1?'启用':'停用'}">状态</td>
                                                <td th:text="${item.title}">问卷标题</td>
                                                <td style="text-align: center;"><button class="layui-btn layui-btn-small layui-btn-normal" th:onclick="|renderItem('${item.id}')|">
                                                        <i class="layui-icon">&#xe615;</i>
                                                    </button> <a class="layui-btn layui-btn-small" th:href="@{/admin/m/ext/vote/edit_{id}.gsp(id=${item.id})}"><i class="layui-icon">&#xe642;</i></a>
                                                    <button class="layui-btn layui-btn-small layui-btn-normal" th:onclick="|deleted('${item.id}')|">
                                                        <i class="layui-icon">&#xe640;</i>
                                                    </button></td>
                                            </tr> -->
											<tr>
												<td style="text-align: center;">序号</td>
												<td>状态</td>
												<td>问卷标题</td>
												<td style="text-align: center;">123</td>
											</tr>
											<tr>
												<td style="text-align: center;">序号</td>
												<td>状态</td>
												<td>问卷标题</td>
												<td style="text-align: center;">123</td>
											</tr>
											<tr>
												<td style="text-align: center;">序号</td>
												<td>状态</td>
												<td>问卷标题</td>
												<td style="text-align: center;">123</td>
											</tr>
											<tr>
												<td style="text-align: center;">序号</td>
												<td>状态</td>
												<td>问卷标题</td>
												<td style="text-align: center;">123</td>
											</tr>
										</tbody>
									</table>
								</div>
							</fieldset>
						</div>
						<div class="layui-inline" style="width: 60%;">
							<fieldset class="layui-elem-field">
								<legend>选项管理</legend>
								<div class="layui-field-box" id="questionItemDiv">
									<table class="layui-table" lay-even="" lay-skin="row">
										<thead id="dataTable">
											<tr>
												<th style="width: 40px">#</th>
												<th>状态</th>
												<th>问卷标题</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
											<!-- <tr th:if="${questionList.records == null or questionList.records.size() == 0}">
                                                <td colspan="4" style="text-align: center;">暂时没有数据</td>
                                            </tr>
                                            <tr th:each="item,items:${questionList.records}">
                                                <td th:text="${questionList.pageSize*(questionList.page-1)+items.index+1}" style="text-align: center;">序号</td>
                                                <td th:text="${item.enabled==1?'启用':'停用'}">状态</td>
                                                <td th:text="${item.title}">问卷标题</td>
                                                <td style="text-align: center;"><button class="layui-btn layui-btn-small layui-btn-normal" th:onclick="|renderItem('${item.id}')|">
                                                        <i class="layui-icon">&#xe615;</i>
                                                    </button> <a class="layui-btn layui-btn-small" th:href="@{/admin/m/ext/vote/edit_{id}.gsp(id=${item.id})}"><i class="layui-icon">&#xe642;</i></a>
                                                    <button class="layui-btn layui-btn-small layui-btn-normal" th:onclick="|deleted('${item.id}')|">
                                                        <i class="layui-icon">&#xe640;</i>
                                                    </button></td>
                                            </tr> -->
											<tr>
												<td style="text-align: center;">序号</td>
												<td>状态</td>
												<td>问卷标题</td>
												<td style="text-align: center;">123</td>
											</tr>
											<tr>
												<td style="text-align: center;">序号</td>
												<td>状态</td>
												<td>问卷标题</td>
												<td style="text-align: center;">123</td>
											</tr>
											<tr>
												<td style="text-align: center;">序号</td>
												<td>状态</td>
												<td>问卷标题</td>
												<td style="text-align: center;">123</td>
											</tr>
											<tr>
												<td style="text-align: center;">序号</td>
												<td>状态</td>
												<td>问卷标题</td>
												<td style="text-align: center;">123</td>
											</tr>
										</tbody>
									</table>
								</div>
							</fieldset>
						</div>
					</div>
					<div id="pageDiv"></div>
				</div>
			</div>
		</div>
		<div th:replace="fragments/footer_admin">底部版权信息等</div>
	</div>
</body>
<div th:replace="fragments/import_js_admin">引入js</div>
<!--/***** 当前页js start *****/-->
<script th:inline="javascript">
    /*<![CDATA[*/
    var result = /*[[${questionList}]]*/;
    $(function(){
        var option = {
            listUrl : /*[[@{/admin/m/ext/vote/list.gsp?}]]*/,
            totalPages : result.totalPages,
            page : result.page,
            param : {
            }
        };
        tg_basePage(option);
    })

    var deleteUrl = /*[[@{/admin/m/ext/vote/delete_{id}.gsp}]]*/;
    function deleted(id) {
        tg_deleteItem(deleteUrl.replace('{id}',id), function(){
            location.reload();
        });
    }
    
    var ItemEditUrlPre = /*[[@{/admin/m/ext/question/editItem_}]]*/'url';
    var addOptionPre = /*[[@{/admin/m/ext/question/addOption_}]]*/'url';
    function loadItemData(questionId) {
        var listUrl = /*[[@{/admin/m/ext/question/itemList.gsp}]]*/'';
        tg_simpleAjaxPost(listUrl, {
            questionId : questionId
        }, function(d) {
            var result = $.parseJSON(d);
            var records = result.records;
            $("#questionItemDiv").html("<br />");
            for (var i = 0; i < records.length; i++) {
                var record = records[i];
                var $divPanel = $('<div class="panel panel-success">').append($('<div class="panel-heading">').append($("<h4>").html(record.title)));
                var $divBody = $('<div class="panel-body"></div>');
                $divBody.append('<a href="' + (addOptionPre + record.id) + '.gsp" data-target="#commonWin" class="btn btn-primary btn-xs" type="button" data-toggle="modal"><i class="fa fa-plus"></i></a>');
                $divBody.append(' <a href="' + (ItemEditUrlPre + record.id) + '.gsp" data-target="#commonWin" class="btn btn-primary btn-xs" type="button" data-toggle="modal"><i class="fa fa-edit"></i></a>');
                $divBody.append(' <button class="btn btn-warning btn-xs" type="button" onclick="deleteItem(\'' + record.id + '\')"><i class="fa fa-trash-o"></i></button>');
                var $table = $('<table class="layui-table" lay-even="" lay-skin="row">');
                $table.append('<tr><td>标题</td><td>类型</td><td>得票数</td><td>操作</td><tr>');
                for (var j = 0; j < record.questionOptions.length; j++) {
                    var optionRecord = record.questionOptions[j];
                    var editUrlPre = /*[[@{/admin/m/ext/question/editOption_}]]*/'url';
                    var $tr = $('<tr>').append($('<td>').html(optionRecord.title)).append($('<td>').html(optionRecord.inputField)).append($('<td>').html(optionRecord.selectCount));
                    $tr.append($('<td>').html(
                            '<a href="' + (editUrlPre + optionRecord.id) + '.gsp" data-target="#commonWin" class="btn btn-primary btn-xs" type="button" data-toggle="modal"><i class="fa fa-edit"></i></a> <button class="btn btn-warning btn-xs" type="button" onclick="deleteOption(\'' + optionRecord.id
                                    + '\')"><i class="fa fa-trash-o"></i></button>'));
                    $table.append($tr);
                }
                $divBody.append($table);
                $divPanel.append($divBody);
                $("#questionItemDiv").append($divPanel);
            }
        });
    }
    
    function renderItem(questionId) {
        $('#addItem').attr('disabled', false);
        $("#questionId").val(questionId);
        loadItemData(questionId);
    }
    /*]]>*/
</script>
<!--/***** 当前页js end *****/-->
</html>